from django.http import JsonResponse
from django.shortcuts import render

# Create your views here.
from APP.admins import models


def admins_index(request):
    return render(request,'admins_index.html')


def chart_list(request):
    return render(request,'chart_list.html')


def chart_list1(request):
    return render(request,'chart_list1.html')


def chart_list2(request):
    return render(request,'chart_list2.html')


def chart_list0(request):
    return render(request,'chart_list0.html')


def charts_bar(request):
    """构造数据line"""
    # 获取所有的IncomeExpense对象
    # income_expense_data = models.IncomeExpense.objects.order_by("-annual_income").all()[:5]
    legend = ["标签1", "标签2", "标签3", "标签4"]
    data =['岗位0', '岗位1', '岗位2', '岗位3', '岗位4', '岗位5']
    data1 =[5, 240, 36, 10, 10, 20]
    data2=[52, 20, 36, 120, 10, 240]
    data3 =[5, 20, 364, 120, 10, 20]
    data4 =[52, 20, 36, 10, 140, 20]
    # for item in income_expense_data:
    #     data.append(item.farmer_id)
    #     data1.append(int(item.labor_population))
    #     data2.append(int(item.dependent_population))
    #     data3.append(float(item.annual_income))
    #     data4.append(float(item.annual_expense))
    data_list = [
        {
            "name": '标签1',
            "type": 'bar',
            "barWidth": 20,
            "data": data1
        },
        {
            "name": '标签2',
            "type": 'bar',
            "barWidth": 20,
            "data": data2
        },
        {
            "name": '标签3',
            "type": 'bar',
            "barWidth": 20,
            "data": data3
        },
        {
            "name": '标签4',
            "type": 'bar',
            "barWidth": 20,
            "data": data4
        }
    ]
    result={
        'status':True,
        'data':{
            "legend":legend,
            "series_list":data_list,
            "x_axis":data
        }
    }

    return JsonResponse(result)


def charts_pie(request):
    """数据构造"""
    # data=models.Farmer.objects.all()
    # data_occ=[]
    # for i in data:
    #     data_occ.append(i.occupation)
    #
    #
    # def group_and_count(lst):
    #     counter = Counter(lst)
    #     res = [{'value': count, 'name': value} for value, count in counter.items()]
    #     return res
    #
    # res1 = group_and_count(data_occ)
    # print(res1)
    res1=[{'value': 12, 'name': "value1"},{'value': 13, 'name': "value2"},{'value': 15, 'name': "value3"}]
    result = {
        'status': True,
        'data':res1
    }

    return JsonResponse(result)


def charts_bar1(request):
    # 获取所有的IncomeExpense对象
    # income_expense_data = models.m_give.objects.order_by("-money_num").all()[:5]
    legend = ["薪资(K)"]
    data =['岗位0', '岗位1', '岗位2', '岗位3', '岗位4', '岗位5']
    data1 = [5, 2, 6, 10, 10, 20]

    # for item in income_expense_data:
    #     data.append(item.name)
    #     data1.append(int(item.money_num))

    data_list = [
        {
            "name": '薪资(K)',
            "type": 'bar',
            "barWidth": 20,
            "data": data1
        },

    ]
    result = {
        'status': True,
        'data': {
            "legend": legend,
            "series_list": data_list,
            "x_axis": data
        }
    }

    return JsonResponse(result)


def charts_bar_type(request):
    """构造数据line"""
    # 获取所有的IncomeExpense对象
    # income_expense_data = models.IncomeExpense.objects.order_by("-annual_income").all()[:5]
    legend = ["标签1", "标签2", "标签3", "标签4"]
    data =['行业0', '行业1', '行业2', '行业3', '行业4', '行业5']
    data1 =[5, 240, 36, 10, 10, 20]
    data2=[52, 20, 36, 120, 10, 240]
    data3 =[5, 20, 364, 120, 10, 20]
    data4 =[52, 20, 36, 10, 140, 20]
    # for item in income_expense_data:
    #     data.append(item.farmer_id)
    #     data1.append(int(item.labor_population))
    #     data2.append(int(item.dependent_population))
    #     data3.append(float(item.annual_income))
    #     data4.append(float(item.annual_expense))
    data_list = [
        {
            "name": '标签1',
            "type": 'bar',
            "barWidth": 20,
            "data": data1
        },
        {
            "name": '标签2',
            "type": 'bar',
            "barWidth": 20,
            "data": data2
        },
        {
            "name": '标签3',
            "type": 'bar',
            "barWidth": 20,
            "data": data3
        },
        {
            "name": '标签4',
            "type": 'bar',
            "barWidth": 20,
            "data": data4
        }
    ]
    result={
        'status':True,
        'data':{
            "legend":legend,
            "series_list":data_list,
            "x_axis":data
        }
    }

    return JsonResponse(result)


def charts_pie_type(request):
    """数据构造"""
    # data=models.Farmer.objects.all()
    # data_occ=[]
    # for i in data:
    #     data_occ.append(i.occupation)
    #
    #
    # def group_and_count(lst):
    #     counter = Counter(lst)
    #     res = [{'value': count, 'name': value} for value, count in counter.items()]
    #     return res
    #
    # res1 = group_and_count(data_occ)
    # print(res1)
    res1=[{'value': 12, 'name': "value1"},{'value': 13, 'name': "value2"},{'value': 15, 'name': "value3"}]
    result = {
        'status': True,
        'data':res1
    }

    return JsonResponse(result)


def charts_bar1_type(request):
    # 获取所有的IncomeExpense对象
    # income_expense_data = models.m_give.objects.order_by("-money_num").all()[:5]
    legend = ["行业排行"]
    data =['行业0', '行业1', '行业2', '行业3', '行业4', '行业5']
    data1 = [5, 2, 6, 10, 10, 20]

    # for item in income_expense_data:
    #     data.append(item.name)
    #     data1.append(int(item.money_num))

    data_list = [
        {
            "name": '行业排行',
            "type": 'bar',
            "barWidth": 20,
            "data": data1
        },

    ]
    result = {
        'status': True,
        'data': {
            "legend": legend,
            "series_list": data_list,
            "x_axis": data
        }
    }

    return JsonResponse(result)


def charts_bar_other(request):
    """构造数据line"""
    # 获取所有的IncomeExpense对象
    # income_expense_data = models.IncomeExpense.objects.order_by("-annual_income").all()[:5]
    legend = ["标签1", "标签2", "标签3", "标签4"]
    data = ['其他0', '其他1', '其他2', '其他3', '其他4', '其他5']
    data1 = [5, 240, 36, 10, 10, 20]
    data2 = [52, 20, 36, 120, 10, 240]
    data3 = [5, 20, 364, 120, 10, 20]
    data4 = [52, 20, 36, 10, 140, 20]
    # for item in income_expense_data:
    #     data.append(item.farmer_id)
    #     data1.append(int(item.labor_population))
    #     data2.append(int(item.dependent_population))
    #     data3.append(float(item.annual_income))
    #     data4.append(float(item.annual_expense))
    data_list = [
        {
            "name": '标签1',
            "type": 'bar',
            "barWidth": 20,
            "data": data1
        },
        {
            "name": '标签2',
            "type": 'bar',
            "barWidth": 20,
            "data": data2
        },
        {
            "name": '标签3',
            "type": 'bar',
            "barWidth": 20,
            "data": data3
        },
        {
            "name": '标签4',
            "type": 'bar',
            "barWidth": 20,
            "data": data4
        }
    ]
    result = {
        'status': True,
        'data': {
            "legend": legend,
            "series_list": data_list,
            "x_axis": data
        }
    }

    return JsonResponse(result)


def charts_pie_other(request):
    """数据构造"""
    # data=models.Farmer.objects.all()
    # data_occ=[]
    # for i in data:
    #     data_occ.append(i.occupation)
    #
    #
    # def group_and_count(lst):
    #     counter = Counter(lst)
    #     res = [{'value': count, 'name': value} for value, count in counter.items()]
    #     return res
    #
    # res1 = group_and_count(data_occ)
    # print(res1)
    res1 = [{'value': 12, 'name': "value1"}, {'value': 13, 'name': "value2"}, {'value': 15, 'name': "value3"}]
    result = {
        'status': True,
        'data': res1
    }

    return JsonResponse(result)


def charts_bar1_other(request):
    # 获取所有的IncomeExpense对象
    # income_expense_data = models.m_give.objects.order_by("-money_num").all()[:5]
    legend = ["排行"]
    data = ['其他0', '其他1', '其他2', '其他3', '其他4', '其他5']
    data1 = [5, 2, 6, 10, 10, 20]

    # for item in income_expense_data:
    #     data.append(item.name)
    #     data1.append(int(item.money_num))

    data_list = [
        {
            "name": '排行',
            "type": 'bar',
            "barWidth": 20,
            "data": data1
        },

    ]
    result = {
        'status': True,
        'data': {
            "legend": legend,
            "series_list": data_list,
            "x_axis": data
        }
    }

    return JsonResponse(result)


